from django import forms

from web import models
from web.forms.base_form import BaseForm


class WikiModeForm(BaseForm, forms.ModelForm):
    class Meta:
        model = models.Wiki
        exclude = ["project", "depth", ]

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        total_data_list = [("", "请选择")]
        # 父文章关联
        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list("id", "title")
        total_data_list.extend(data_list)
        self.fields["parent"].choices = total_data_list
